package com.lagou.springboot.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lagou.springboot.mapper.ArticleMapper;
import com.lagou.springboot.pojo.Article;
import com.lagou.springboot.pojo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    ArticleMapper articleMapper;

    @Override
    public PageResult<Article> findAllArticles(int currentPage) {

        // 分页插件设置(固定每页3个)
        PageHelper.startPage(currentPage, 2);

        // 调用
        Page<Article> articlesPage = articleMapper.selectAll();

        // 返回page设置
        return new PageResult<Article>(articlesPage.getPages(), articlesPage.getResult());
    }
}
